//
//  WCG_O_sectionHeaderView.m
//  Project_B
//
//  Created by 黑黑 on 15/11/25.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "WCG_O_sectionHeaderView.h"
#import "Masonry.h"
//边界
#define kSpecialHeaderSideBorder 15
//黄色图标边长
#define kYellowImageViewSize 42
//文本高夫
#define kLabelHeight kYellowImageViewSize/2
//黄色图与文本间隔
#define ktitleLeftBorder 5
//文本宽
#define kLabelWidth 140
@interface WCG_O_sectionHeaderView ()

@property (nonatomic, retain) UIImageView *yellowImageView;
@property (nonatomic, retain) UILabel *specialCharLabel;
@property (nonatomic, retain) UILabel *specialEngNameLabel;
@property (nonatomic, retain) UILabel *specialNameLabel;

@end

@implementation WCG_O_sectionHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        BOOL isNight = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
        
        self.backgroundColor = isNight ? [UIColor blackColor] : [UIColor whiteColor];
        
        self.yellowImageView = [[UIImageView alloc] init];
        self.yellowImageView.image = [UIImage imageNamed:@"icon-special-number"];
        self.yellowImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.yellowImageView.layer.masksToBounds = YES;
        [self addSubview:self.yellowImageView];
        [self.yellowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.left.mas_equalTo(self.mas_left).with.offset(kSpecialHeaderSideBorder);
            make.size.mas_equalTo(kYellowImageViewSize);
        }];
        
        self.specialCharLabel = [[UILabel alloc] init];
        self.specialCharLabel.textAlignment = NSTextAlignmentCenter;
        self.specialCharLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.specialCharLabel];
        [self.specialCharLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.yellowImageView.mas_centerX);
            make.centerY.mas_equalTo(self.yellowImageView.mas_centerY);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        
        self.specialEngNameLabel = [[UILabel alloc] init];
        self.specialEngNameLabel.font = [UIFont systemFontOfSize:12];
        self.specialEngNameLabel.textColor = isNight ? kNightColor_SuggestTitle : kDayColor_SuggestTitle;
        [self addSubview:self.specialEngNameLabel];
        [self.specialEngNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.yellowImageView.mas_top).with.offset(0);
            make.left.mas_equalTo(self.yellowImageView.mas_right).with.offset(10);
            make.width.mas_equalTo(150);
            make.height.mas_equalTo(18);
        }];
        
        self.specialNameLabel = [[UILabel alloc] init];
        self.specialNameLabel.font = [UIFont systemFontOfSize:14];
        self.specialNameLabel.textColor = isNight ? kNightColor_SuggestTitle : kDayColor_SuggestTitle;
        [self addSubview:self.specialNameLabel];
        [self.specialNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.yellowImageView.mas_right).with.offset(10);
            make.top.mas_equalTo(self.specialEngNameLabel.mas_bottom).with.offset(0);
            make.width.mas_equalTo(150);
            make.bottom.mas_equalTo(self.yellowImageView.mas_bottom).with.offset(0);
        }];
        
        self.specialNumLabel = [[UILabel alloc] init];
        self.specialNumLabel.textAlignment = NSTextAlignmentRight;
        self.specialNumLabel.font = [UIFont systemFontOfSize:13];
        self.specialNumLabel.textColor = isNight ? kNightColor_SuggestTitle : kDayColor_SuggestTitle;
        [self addSubview:self.specialNumLabel];
        [self.specialNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.right.mas_equalTo(self.mas_right).with.offset(-35);
            make.width.mas_equalTo(150);
            make.height.mas_equalTo(30);
        }];
        
        self.arrowImageView = [[UIImageView alloc] init];
        self.arrowImageView.image = isNight ? [UIImage imageNamed:@"icon-arrow-right-yellow"] : [UIImage imageNamed:@"icon-update-arrow-right-black"];
        [self addSubview:self.arrowImageView];
        [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.right.mas_equalTo(self.mas_right).with.offset(-15);
            make.width.mas_equalTo(15);
            make.height.mas_equalTo(25);
        }];
    }
    return self;
}

- (void)setCategoryModel:(GXSpecialCategoryListModel *)categoryModel
{
    if (_categoryModel != categoryModel) {
        _categoryModel = categoryModel;
    }
    self.specialCharLabel.text = [_categoryModel.category_ename substringToIndex:1];
    self.specialEngNameLabel.text = _categoryModel.category_ename;
    self.specialNameLabel.text = _categoryModel.category_name;
    self.specialNumLabel.text = [NSString stringWithFormat:@"看全部%@个专题", _categoryModel.special_num];
}
// 代理人实现协议方法
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.delegate clickSectionView:self.categoryModel];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
